/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package utilidades;

import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;

/**
 *
 * @author Mauricio
 */
public class ValidaDecimal extends KeyAdapter {

    @Override
    public void keyTyped(KeyEvent e) {
        char caracter = e.getKeyChar();

        if ((caracter < '0' || caracter > '9') && (caracter != KeyEvent.VK_BACK_SPACE || caracter != KeyEvent.VK_DELETE) && caracter != '.') {
            e.consume();
        }
    }

    public static float roundNum(float num) {

        float valor = 0;
        int aux = 0;

        valor = num;

        aux = (int) (valor * 1000);
        //valor = java.lang.Math.round(valor);
        valor = (float) (aux / 1000.0);
        return valor;

    }
}
